#ifndef __UTILITY_H__
#define __UTILITY_H__

#include "StructDef.h"
#include "Common/Debug.h"
#include "Common/Utili.h"
#include "Common/Memory.h"

#ifndef MAP_TW
	#include "MapData_Foreign/Utility_f.h"
#endif
// for message box
#define	MESSAGE_OK			0
#define	MESSAGE_WAIT		1
#define	MESSAGE_WARNING		2

#ifdef __cplusplus
extern "C" {
#endif

#define EndOfLine( ptr )	(( *((char *)(ptr)) == 10 ) || ( ( *((char *)(ptr)) == 13 && *((char *)(ptr+1)) == 10 ) || *((char *)(ptr)) == 10 ) )
#define IsSpace( ptr )		(*((char *)(ptr)) == 32 )
#define IsTab( ptr ) 		(*((char *)(ptr)) == 9 )
#define IsQuote( ptr )		(*((char *)(ptr)) == '"' )
#define IsComma( ptr )		(*((char *)(ptr)) == ',' )
#define EndOfFile( ptr)		(*((char *)(ptr)) == 0 )

#define		MAP_TO_VIEW		(0)
#define		VIEW_TO_MAP		(1)

#define		PROGRESS_UNKNOW	(-1)
#define		PROGRESS_MENU	(0)
#define		PROGRESS_MAP	(1)
#define		UT_TMPBUFFSIZE	(1024*1024)

int			ut_IntersectPt2Line(TPosCoor pos, TPosCoor pos1, TPosCoor pos2, TPosCoor* pIntersect, int* pDirFlag);
void		ut_SetPosChangeOffset(int offsetX, int offsetY);
void		ut_GetPosChangeOffset(int *offsetX, int *offsetY);
void		ut_IntersectionPosChange(TPosCoor *pMapPos, TPosCoor *pViewPos, TRefreshInfo RefreshInfo);
int			ut_GetRoughDistance(TPosCoor pos, TPosCoor Boundary[2]);
int			ut_GetTwoRoadAngle(TOptPathPos Road, TOptPathPos NextRoad, BOOL bExpand);
int			ut_GetLineAngle(int x1, int y1, int x2, int y2);
int			ut_Deg2Pos(int deg, int fen, int miao);
int			ut_GetAngleDiff(int angle1, int angle2);
BOOL		ut_IsPosValid(TPosCoor pos);
TPosCoor	ut_GetNormalPos(TPosCoor BasePos, TPosCoor RefPos, int iDis);
TPosCoor	ut_ShiftPos(TPosCoor BasePos, TPosCoor RefPos, int iDis);
int			ut_CalcToBlockDist(TPosCoor PointPos, TPosCoor RectPos1, TPosCoor RectPos2);
int			ut_GetSign(int iAngle);
BOOL		ut_PtInRect(TPosCoor pos, TRect rect);
BOOL		ut_LineInRect(TPosCoor pos1, TPosCoor pos2, TRect rect);
BOOL		ut_CutShowName(char *pszCurrName, char *pszShowName, int iMaxLen);
void		ut_GetWordName(char *pszWordName, char* pszName);
int			ut_GetWordClass(char* pszName);
int			ut_Pos2Deg(int pos);
int			ut_Pos2Fen(int pos);
int			ut_Pos2Miao(int pos);
int			ut_GetWordCount(char* pszText);
char*		ut_itoa(int value, char* buf);
int			ut_StrBreakLine(char *pszName1, char *pszName2, int LineMaxChar);
int			ut_CompareName(const void* arg1, const void* arg2);
void		ut_LineFitRect(TPosCoor* pBeginPos, TPosCoor* pEndPos, TRect* pRect);
BOOL		ut_LinesIntersection(TPosCoor L1Pos1, TPosCoor L1Pos2, TPosCoor L2Pos1, TPosCoor L2Pos2, TPosCoor* pIntersect);
void		ut_BufScanf(char **Ptr, char *str);

/* these function are planed to move to MenuTool.c as menu_xxx(),
   plz don't use it any more when it done -OB */	

//Time
void ut_TimeToHourMin(int* piHour, int* piMin, int iTime, char *time_param);	// iTime is gps ticks
int  ut_GetTime(int* piHour, int* piMin, int* piSec);
int  ut_GetDate(int* piYear, int *piMonth, int* iDay);
void ut_TimeAddTime(int* piHour, int* piMin, int iTime1, int iTime2);

// Platform/os includes
#if defined WIN_PC
#include "Win32/Thread.h"
#include "Win32/RealTime.h"
#include "Win32/Input.h"
#include "Win32/MP3.h"
#include "Win32/PIC.h"
#elif defined WIN_CE
#include "WinCE/Thread.h"
#include "WinCE/RealTime.h"
#include "WinCE/Input.h"
#include "WinCE/MP3.h"
#include "WinCE/PIC.h"
#else
#include "Thread.h"
#include "RealTime.h"
#include "Input.h"
//#include "MP3.h"
//#include "PIC.h"
#endif

#if defined _TOUCH_PANEL && defined _BF533
#include "BF533/TouchPanel.h"
#endif

#if defined _TOUCH_PANEL && defined _DAVINCI
#include "DAVINCI/TouchPanel.h"
#endif

///
char* ut_LineFeed(char *ptr, int iLength, int iLines, int *pLinePos);
BOOL ut_IsChineseWord( char *pszText );
int ut_SortWord(const void *arg1, const void *arg2);
#ifdef __cplusplus
}
#endif

#endif
